import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// import indexPage from '../views/index.vue'
// import loginPage from '../views/Login.vue'

const routes = [
    { path:'/', redirect:'/index'},
    { 
        path: '/index',
        component:() =>  import('../views/index'),
        redirect:'/index/banner',
        meta: { title: '首页' },
        children: [
            //首页管理
            { path: 'banner', 
            meta: { title: '轮播图管理' }, 
            component:() => import('../views/shouye/banner'),
            beforeEnter: (to, from, next) => {
                // reject the navigation
                console.log('独享守卫')
                next()
              },
         },
            { path: 'category', meta: { title: '分类区管理' }, component:() => import('../views/shouye/category') },
            { path: 'recommend', meta: { title: '为你推荐管理' }, component:() => import('../views/shouye/recommend') },
            //商品管理
            { path: 'sort', meta: { title: '分类管理' }, component:() => import('../views/shangpin/sort') },
            { path: 'brand', meta: { title: '品牌管理' }, component:() => import('../views/shangpin/brand') },
            { path: 'product', meta: { title: '商品管理' }, component:() => import('../views/shangpin/product') },
            //新闻管理
            { path: 'news', meta: { title: '新闻管理' }, component:() => import('../views/xinwen/news') },
        ]
 },
    { path: '/login', component:() => import('../views/Login') },
]

const router = new VueRouter({
    routes, // `routes: routes` 的缩写
})

router.beforeEach((to, from, next) => {
    // ...
    // 返回 false 以取消导航
    // return false
    next()
  })

export default router